package com.google.code.p.restrpc.client.proxy;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.google.code.p.restrpc.RestInvoker;
import com.google.code.p.restrpc.RestInvokerFactory;
import com.google.code.p.restrpc.http.CachedHttpClientFactory;
import com.google.code.p.restrpc.http.DefaultHttpClientFactory;
import com.google.code.p.restrpc.http.RestTemplate;

/**
 * @author dz
 */
public class RestfulRpcInvokerFactory implements RestInvokerFactory {
    
    private Properties properties = new Properties();
    
    /**
     * 
     */
    public RestfulRpcInvokerFactory() {
        InputStream is = RestfulRpcInvokerFactory.class.getResourceAsStream("/http.client.properties");
        if (is != null) {
            try {
                properties.load(is);
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
    /**
     * @param properties
     */
    public RestfulRpcInvokerFactory(Properties properties) {
        this.properties = properties;
    }
    
    /**
     * 
     */
    public RestInvoker getRestInvoker() {
        return new DefaultRestInvoker(new RestTemplate(new CachedHttpClientFactory(new DefaultHttpClientFactory(properties))));
    }
    
}
